//
//  BMMergeViews.m
//  bigmama
//
//  Created by ren on 16/2/1.
//  Copyright © 2016年 . All rights reserved.
//

#import "BMMergeViews.h"


@interface BMMergeViews ()
@property(nonatomic,strong) NSArray *arrayViews;
@property (nonatomic, assign) NSInteger originY;
@end

@implementation BMMergeViews
- (instancetype)initWithMergeView:(NSArray *)arrayViews
{
    self.arrayViews = arrayViews;
    NSInteger height = [self heightForView];
    self = [super initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, height)];
    if (self) {
        [self addSubviews];
    }
    return self;
}

- (instancetype)initWithMergeView:(NSArray *)arrayViews originY:(NSInteger)originY
{
    self.arrayViews = arrayViews;
    self.originY = originY;
    NSInteger height = [self heightForView];
    self = [super initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, height)];
    if (self) {
        [self addSubviews];
    }
    return self;
}

- (NSInteger)heightForView
{
    NSInteger height = self.originY;
    for (UIView *view in self.arrayViews) {
        if ([view isKindOfClass:[UIView class]]) {
            height += view.height;
        }
    }
    if (height == self.originY) {
        return 0;
    }
    return height;
}

- (void)addSubviews
{
    self.backgroundColor = [UIColor whiteColor];
    
    NSInteger height = self.originY;
    for (UIView *view in self.arrayViews) {
        view.y = height;
        [self addSubview:view];
         height += view.height;
    }

}

@end
